<template>
  <a-modal :maskClosable="false"
    :title="title"
    :width="1024"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" v-bind="layout" :model="model" :rules="validatorRules">
        <a-form-model-item label="订单号">
           {{model.orderNo}}
        </a-form-model-item>
        <a-form-model-item label="发货类型">
          <a-select v-model="model.deliverSource" placeholder="请选择发货类型" required prop="deliverSource">
            <a-select-option value="0">现场取货</a-select-option>
            <a-select-option value="30">物流快递</a-select-option>
            <a-select-option value="20">商家配送</a-select-option>
          </a-select>
        </a-form-model-item>
        <a-form-model-item label="快递名称"  v-if="model.deliverSource=='30'">
          <a-input placeholder="请输入快递名称" v-model="model.linkman" />
        </a-form-model-item>
        <a-form-model-item label="快递单号" v-if="model.deliverSource=='30'">
          <a-input placeholder="请输入快递单号" v-model="model.deliverNo" />
        </a-form-model-item>

        <a-form-model-item label="送货电话"  v-if="model.deliverSource=='20'">
          <a-input placeholder="请输入送货电话" v-model="model.phone" />
        </a-form-model-item>
        <a-form-model-item label="送货人" v-if="model.deliverSource=='20'">
          <a-input placeholder="请输入送货人" v-model="model.linkman" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import { httpAction, putAction, getAction, postAction, getFileAccessHttpUrl } from '@/api/manage'
import JImageUpload from '@/components/jeecg/JImageUpload'

export default {
  name: 'ordStoreInfoModal',
  components: {
    JImageUpload
  },
  data() {
    return {
      title: '操作',
      visible: false,
      isEdit: false,
      model: {
        deliverSource:"0",
      },
      layout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 12 }
      },
      confirmLoading: false,
      validatorRules: {
        deliverSource: [{ required: true, message: '请选择发货类型!' }],
      },
      url: {
        add: '/store/order/sure/delivery',
        edit: '/store/order/sure/delivery'
      },
      fileList: []
    }
  },
  created() {
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    edit(record) {
      this.model.orderNo=record.orderNo;
      this.visible = true
      this.isEdit = true
    },
    close() {
      this.$refs.form.clearValidate()
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          if (that.fileList != '') {
            this.model.avatar = that.fileList
          } else {
            this.model.avatar = ''
          }

          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
              that.close()
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
          })
        } else {
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    },
    getAvatarView: function(avatar) {
      return getFileAccessHttpUrl(avatar)
    }

  }
}
</script>

<style scoped>

</style>
